/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NotifyStock.java
 *
 * Created on Nov 4, 2010, 10:47:23 PM
 */

package lmclogistics;

import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import sql.Sql;

/**
 *
 * @author katrina
 */
public class NotifyStock extends javax.swing.JFrame {

    /** Creates new form NotifyStock */
    public NotifyStock() {
        initComponents();
        setTitle("Notify Remaining Stocks");
        setLocationRelativeTo(null);
        setSize(305, 350);
        setResizable(false);
        setAlwaysOnTop(true);
        setVisible(true);
        setValues();

        BufferedImage image = null;
        try {
            image = ImageIO.read(getClass().getResource("/images/favicon.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        setIconImage(image);
    }

    public void setValues()
    {
        try
        {
            String query20 = "SELECT count(*) AS 'twenty' FROM chassis WHERE chsSize = '20' AND deleted=0";
            String query40 = "SELECT count(*) AS 'forty' FROM chassis WHERE chsSize = '40' AND deleted=0";
            String queryCombo = "SELECT count(*) AS 'combo' FROM chassis WHERE chsSize = 'c' AND deleted=0";
            String queryTotal = "SELECT count(*) AS 'total' FROM chassis WHERE deleted=0";

            Connection connection = Sql.getSqlConnection();
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery(query20);           

            rs.next();            
            stock20.setText(rs.getString("twenty"));

            rs = stmt.executeQuery(query40);
            rs.next();
            stock40.setText(rs.getString("forty"));

            rs = stmt.executeQuery(queryCombo);
            rs.next();
            stockCombo.setText(rs.getString("combo"));

            rs = stmt.executeQuery(queryTotal);
            rs.next();
            stockTotal.setText(rs.getString("total"));

            Sql.closeSqlConnection(connection);

        }
        catch (Exception ex) {
            Logger.getLogger(Chassis.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        stock20 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        stock40 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        stockCombo = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        stockTotal = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Remaining Stocks:");

        stock20.setText("20");

        jLabel3.setText("size 20");

        stock40.setText("45");

        jLabel5.setText("size 40");

        stockCombo.setText("10");

        jLabel7.setText("size c");

        jLabel8.setText("TOTAL");

        stockTotal.setText("75");

        jLabel10.setText("----------------------------------");

        jButton1.setText("Ok");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(stock40)
                                .addGap(93, 93, 93)
                                .addComponent(jLabel5))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(stock20)
                                .addGap(93, 93, 93)
                                .addComponent(jLabel3))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(stockCombo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel7))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(stockTotal)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel8))
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(105, 105, 105)
                        .addComponent(jButton1)))
                .addContainerGap(77, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jLabel1)
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(stock20)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(stock40)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(stockCombo))
                .addGap(2, 2, 2)
                .addComponent(jLabel10)
                .addGap(2, 2, 2)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(stockTotal))
                .addGap(38, 38, 38)
                .addComponent(jButton1)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel stock20;
    private javax.swing.JLabel stock40;
    private javax.swing.JLabel stockCombo;
    private javax.swing.JLabel stockTotal;
    // End of variables declaration//GEN-END:variables

}
